<include file="Common/head" />
<link rel="stylesheet" href="__PUBLIC__/css/weixin/iconfont.css">
<script src="__PUBLIC__/js/weixin/mui.pullToRefresh.js?v=1.1"></script>
<script src="__PUBLIC__/js/weixin/mui.pullToRefresh.material.js?v=1.1"></script>
<div id="listContentScroll" class="mui-content mui-scroll-wrapper pb50">
    <div class="mui-scroll">

        <ul class="reserve-list" id="data-list">

        </ul>

    </div>
</div>
<script type="text/javascript">
    var curPage = 1;

    mui.init();

    mui("#listContentScroll .mui-scroll").pullToRefresh({
        up: {
            auto: true,
            contentrefresh: '正在加载...',
            contentnomore: '',
            contentdown: '',
            callback: function() {
                loadList(this);
            }
        }
    });

    function loadList(obj) {
        mui.getJSON(apiUrl+'/Appointment/getList',{p: curPage},function(cbData) {
            if (cbData.code == 200) {
                var data = cbData.data.list;
                var totalPage = parseInt(cbData.data.totalPage);
                if (isNaN(totalPage)) {
                    totalPage = 0;
                }
                if (data.length > 0) {
                    var html = '';
                    mui.each(data, function (index, item) {
                        var aHtml = '';
                        switch (item.status) {
                            case "0":
                                aHtml = '<span class="btn btn1">已取消</span>';
                                break;
                            case 1:
                                //aHtml = '未开始';
                                aHtml = '<span class="btn btn2" data-id="'+item.id+'">取消</span>';
                                break;
                            case 2:
                                aHtml = '<span class="btn btn3">已结束</span>';
                                break;
                            case 3:
                                aHtml = '<span class="btn btn4">进行中</span>';
                                break;
                            default:
                                aHtml = '<span class="btn btn5">正常</span>';
                                break;
                        }
                        html += '<li class="reserve-item">';
                        html += '<div class="title layout-center">';
                        html += '<div class="tit flex-item1 mui-ellipsis">'+item.org.name+'</div>'+aHtml;
                        html += '</div>';
                        html += '<div class="cont">';
                        html += '<div class="text">';
                        html += '<label><i class="iconfont icon-yonghu1"></i>服务用户：</label><span>'+item.user.real_name+'</span>';
                        html += '</div>';
                        html += '<div class="text">';
                        html += '<label><i class="iconfont icon-shijian"></i>预约时间：</label><span>'+baseTool.formatDate(item.order_time,"yyyy-MM-dd")+' '+item.time_range+'</span>';
                        html += '</div>';
                        html += '<div class="text">';
                        html += '<label><i class="iconfont icon-yuyueshixiang"></i>预约事项：</label><span>'+baseTool.formatEmpty(item.content)+'</span>';
                        html += '</div>';
                        html += '</div>';
                        html += '</li>';
                    });
                    $("#data-list").append(html);
                } else {
                    if (totalPage < 1) {
                        var html = '';
                        html += '<li class="nobox">';
                        html += '<img src="'+serverName+'/Public/images/no-data.png">';
                        html += '</li>';
                        $("#data-list").html(html);
                    }
                }
                var noMore = curPage < totalPage ? false : true;
                obj.endPullUpToRefresh(noMore);
                curPage = cbData.data.curPage;
            }
        });
    }

    mui(".mui-scroll-wrapper").scroll({
        deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });

    mui("#data-list").on('tap','.btn2',function(){
        var btnArray = ["否", "是"];
        var id = this.getAttribute("data-id");
        mui.confirm("确认取消该预约吗？", "确认", btnArray, function(e) {
            if (e.index == 1) {
                mui.getJSON(apiUrl+'/Appointment/cancelBespeak',{id: id},function(cbData) {
                    mui.toast(cbData.msg,{duration:'long'});
                    if (cbData.code == 200) {
                        setTimeout(function () {
                            location.reload();
                        },3000);
                    }
                });
            }
        });
    });

</script>
<include file="Common/footer" />